import {btnMetas} from "@/metas/ComponentMetas";
import {ComponentType} from "@/store/consts";
import {BooleanData, FunViewData, MethodData} from "@/components/OptionsMetaData";
import {EventBus, EventType} from "@/event";
const EditFunData = [
    {label: '自定义', value: ''},
    {label: '提交', value: 'submit'},
    {label: '取消', value: 'cancel'},
    {label: '重置', value: 'reset'},
]

const SearchFunData = [
    {label: '自定义', value: ''},
    {label: '搜索', value: 'query'},
    {label: '新增', value: 'add'},
    {label: '修改', value: 'update'},
    {label: '删除', value: 'del'},
    {label: '导入', value: 'import'},
    {label: '导出', value: 'export'},
]

const EditFunBtnTabMetas = {
    basic: {label: '基础配置', metas: [
            {title: '名称', field: 'title', type: 'text', default: '功能按钮', required: true},
            {title: '功能', field: 'funs', type: 'sig'
                , input: {field: 'funName', type: 'text', title: '方法名称'}
                , select: {field: 'funs', type: 'select', data: EditFunData
                    , change(val, meta, model) {
                        let option = this.data.find(item => item.value == val ? item : null);
                        model['funName'] = val;
                        model['title'] = option ? option['label'] : model['title'];
                    }, default: ''}
                , realField: ['funName']
            },
            {title: '功能地址', field: 'url', type: 'sig'
                , input: {field: 'url'}
                , select: {field: 'method', data: MethodData}
                , realField: ['url', 'method']
            },
            {title: '按钮组件配置', field: 'desc', type: 'divider'},
            ...btnMetas
        ]
    }
}

const SearchFunBtnTabMetas = {
    basic: {label: '基础配置', metas: [
            {title: '名称', field: 'title', type: 'text', default: '功能按钮', required: true},
            {title: '功能', field: 'funs', type: 'sig'
                , input: {field: 'funName', type: 'text', title: '方法名称'}
                , select: {field: 'funs', type: 'select', data: SearchFunData
                    , change(val, meta, model) {
                        let option = this.data.find(item => item.value == val ? item : null);
                        model['funName'] = val;
                        model['title'] = option ? option['label'] : model['title'];
                    }, default: ''}
                , realField: ['funName']
            },
            {title: '功能地址', field: 'url', type: 'sig'
                , input: {field: 'url'}
                , select: {field: 'method', data: MethodData}
                , realField: ['url', 'method']
            },
            {title: '是否多选', field: 'batch', type: 'radio', data: BooleanData, default: false
                , change(val, meta, model) {
                    EventBus.publish(EventType.funBatch, meta)
                }
            },
            {title: '显示到', field: 'funViewTo', type: 'radio', data: FunViewData
                , default: 'search', change(val, meta, model) {
                    EventBus.publish(EventType.funViewTo, meta)
                }},
            {title: '按钮组件配置', field: 'desc', type: 'divider'},
            ...btnMetas
        ]
    }
}

function getFunTabMetas(type) {
    if(type == ComponentType.Edit) {
        return EditFunBtnTabMetas;
    } else if(type == ComponentType.Search) {
        return SearchFunBtnTabMetas;
    }
}

export {SearchFunData, getFunTabMetas}
